package com.iemes.controller.mould;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.PrepareFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.mould.PrepareMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
import com.iemes.util.MyDateUtils;

@RequestMapping("/prepare/")
@Controller
public class PrepareController extends BaseController {

	@Inject
	private PrepareMapper prepareMapper;
	
	@RequestMapping("examineOrder")
	public String examineOrder(Model model){
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/mould/prepare/prepare_list";
	}
	
	@ResponseBody
	@RequestMapping("prepare_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception
	{
		PrepareFormMap prepareFormMap = getFormMap(PrepareFormMap.class);
		List<Map<String, Object>> prepare = prepareMapper.getAll(prepareFormMap);
		LuogicPaging(pageNow, pageSize, prepare);
		return pageView;
	}
	
	@RequestMapping("prepare_edit")
	public String editUI(Model model) throws Exception 
	{
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			PrepareFormMap prepare = prepareMapper.getById(id);
			model.addAttribute("prepare",prepare);
		}
		return Common.BACKGROUND_PATH + "/mould/prepare/prepare_edit";
	}
	
	@ResponseBody
	@RequestMapping(value="prepare_editEntity")
	@SystemLog(module="备模指令",methods="备模指令表-修改备模指令表")//凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		PrepareFormMap prepareFormMap = getFormMap(PrepareFormMap.class);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date();
		prepareFormMap.put("date", sdf.format(date));
		// 获取request
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  
		// 通过工具类获取当前登录的bean
		UserFormMap userFormMap = (UserFormMap)Common.findUserSession(request);
		prepareFormMap.put("fillPeopleId", userFormMap.getInt("id"));
		prepareMapper.editEntity(prepareFormMap);
		return "success";
	}
}











